/*
 * Copyright 2003-2007 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

package com.colony.networkvm.machine;

import java.util.Stack;

/**
 * A NvmStack is a dual stack of objects and object types.  Both the
 * type and the id are stored on the stack.  
 */
public class NvmStack
{	
	public static final String TYPENAME = "stack";
	
	private Stack _stack;

	public NvmStack(  )
	{
		_stack = new Stack();
	}
	
	public void push( int id, Object o )
	{
		NvmStackElement element = new NvmStackElement();
		element.o = o;
		element.id = id;
		
		_stack.push( element );
	}

	public Object pop()
	{
		NvmStackElement element = (NvmStackElement) _stack.pop();
		return element.o;
	}
	
	public int peekId()
	{
		NvmStackElement element = (NvmStackElement) _stack.peek();
		return element.id;
	}
	
	public Object peek()
	{
		NvmStackElement element = (NvmStackElement) _stack.peek();
		return element.o;
	}
	
	public int size()
	{
		return _stack.size();
	}
	
	public boolean empty()
	{
		return _stack.empty();
	}
	
	private static class NvmStackElement
	{
		public Object o;
		public int id;
	}
}
